package com.anyou.mall.sho.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.anyou.common.annotation.ShopScope;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.anyou.common.annotation.Log;
import com.anyou.common.core.controller.BaseController;
import com.anyou.common.core.domain.ApiResult;
import com.anyou.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.anyou.mall.sho.domain.ShoShopAddress;
import com.anyou.mall.sho.service.IShoShopAddressService;
import com.anyou.common.utils.poi.ExcelUtil;
import com.anyou.common.core.page.TableDataInfo;

/**
 * 商家退换货地址Controller
 *
 * @author xq
 * @date 2022-04-15
 */
@Api(tags = "商家退换货地址")
@RestController
@RequestMapping("/sho/shoAddress")
public class ShoShopAddressController extends BaseController
{
    @Autowired
    private IShoShopAddressService shoShopAddressService;

    /**
     * 查询商家退换货地址列表
     */
    @ApiOperation("查询商家退换货地址列表")
    @PreAuthorize("@ss.hasPermi('sho:shoAddress:list')")
    @GetMapping("/list")
    @ShopScope(baseTableAlias="a")
    public TableDataInfo<List<ShoShopAddress>> list(ShoShopAddress shoShopAddress)
    {
        startPage();
        List<ShoShopAddress> list = shoShopAddressService.selectShoShopAddressList(shoShopAddress);
        return getDataTable(list);
    }

    /**
     * 导出商家退换货地址列表
     */
    @ApiOperation("导出商家退换货地址列表")
    @PreAuthorize("@ss.hasPermi('sho:shoAddress:export')")
    @Log(title = "商家退换货地址", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ShopScope(baseTableAlias="a")
    public void export(HttpServletResponse response, ShoShopAddress shoShopAddress)
    {
        List<ShoShopAddress> list = shoShopAddressService.selectShoShopAddressList(shoShopAddress);
        ExcelUtil<ShoShopAddress> util = new ExcelUtil<ShoShopAddress>(ShoShopAddress.class);
        util.exportExcel(response, list, "商家退换货地址数据");
    }

    /**
     * 获取商家退换货地址详细信息
     */
    @ApiOperation("获取商家退换货地址详细信息")
    @PreAuthorize("@ss.hasPermi('sho:shoAddress:query')")
    @GetMapping(value = "/{carPartsShopId}")
    @ApiImplicitParams({
            @ApiImplicitParam(name="carPartsShopId",dataType="Long",required=true,value="汽配商编号"),
    })
        public ApiResult<ShoShopAddress> getInfo(@PathVariable("carPartsShopId") Long carPartsShopId)
    {
        return ApiResult.success(shoShopAddressService.selectShoShopAddressByAddressId(carPartsShopId));
    }

    /**
     * 新增商家退换货地址
     */
    @ApiOperation("新增 修改 商家退换货地址")
    @PreAuthorize("@ss.hasPermi('sho:shoAddress:add')")
    @Log(title = "商家退换货地址", businessType = BusinessType.INSERT)
    @PostMapping
    public ApiResult add(@RequestBody ShoShopAddress shoShopAddress)
    {
        return ApiResult.success(shoShopAddressService.insertShoShopAddress(shoShopAddress));
    }

    /**
     * 修改商家退换货地址
     */
/*    @ApiOperation("修改商家退换货地址")
    @PreAuthorize("@ss.hasPermi('sho:shoAddress:edit')")
    @Log(title = "商家退换货地址", businessType = BusinessType.UPDATE)
    @PutMapping
    public ApiResult edit(@RequestBody ShoShopAddress shoShopAddress)
    {
        return ApiResult.success(shoShopAddressService.updateShoShopAddress(shoShopAddress));
    }*/

    /**
     * 删除商家退换货地址
     */
    @ApiOperation("删除商家退换货地址")
    @PreAuthorize("@ss.hasPermi('sho:shoAddress:remove')")
    @Log(title = "商家退换货地址", businessType = BusinessType.DELETE)
    @DeleteMapping("/{addressIds}")
    public ApiResult remove(@PathVariable Long[] addressIds)
    {
        return ApiResult.success(shoShopAddressService.deleteShoShopAddressByAddressIds(addressIds));
    }
}
